package Interface;


import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;


public class MainInterface extends JFrame {

    JLabel topLabel;
    JLabel Label;
    JLabel dayLabel;


    JTextArea textArea;
    JPanel mainPanel;
    JPanel eventPanel;

    JPanel buttonPanel;
    JButton button1;
    JButton button2;
    JButton button3;
    JButton button4;


    JPanel wupingPanel;
    JPanel leftwupingPanel;
    JPanel rightwupingPanel;

    JTextArea foodLabel1;
    JTextArea daojuLabel1;

    String message = "";

    public MainInterface() {
        //游戏框
        setSize(1600, 1100);
        setVisible(true);
        setLayout(null);


        //顶上显示天数和玩家状态
        topLabel = new JLabel();
        topLabel.setOpaque(true);
        topLabel.setBackground(Color.cyan);
        add(topLabel);
        topLabel.setBounds(0, 0, 1400, 100);

        dayLabel = new JLabel();
        dayLabel.setOpaque(true);
        dayLabel.setBackground(Color.YELLOW);
        add(dayLabel);
        dayLabel.setBounds(1400, 0, 200, 100);

        //游戏界面标签，放背景图
        Label = new JLabel();
        Label.setOpaque(true);
        Label.setBackground(Color.black);

        Label.setBounds(0, 0, 1600, 1000);


        //游戏界面，放选项和突发事件的框
        mainPanel = new JPanel();
        add(mainPanel);
        mainPanel.setLayout(null);
        mainPanel.setBackground(Color.white);
        mainPanel.add(Label);

        mainPanel.setBounds(0, 100, 1600, 1000);

        //事件的总容器
        eventPanel = new JPanel();
        eventPanel.setLayout(null);
        eventPanel.setBackground(Color.blue);
        mainPanel.add(eventPanel);
        eventPanel.setBounds(200, 50, 1200, 450);

        //文本框事件描述
        textArea = new JTextArea();
        textArea.setLayout(null);
        eventPanel.add(textArea);
        textArea.setText("事件描述");
        textArea.setBackground(Color.white);
        textArea.setBounds(0, 0, 1200, 300);


        //放选项的容器
        buttonPanel = new JPanel();
        mainPanel.add(buttonPanel);
        buttonPanel.setLayout(null);
        buttonPanel.setBackground(Color.RED);
        buttonPanel.setBounds(200, 350, 1200, 300);


        //底下存放物品
        wupingPanel = new JPanel();
        wupingPanel.setLayout(null);
        wupingPanel.setBackground(Color.yellow);
        mainPanel.add(wupingPanel);
        wupingPanel.setBounds(0, 700, 1600, 300);


        leftwupingPanel = new JPanel();
        leftwupingPanel.setLayout(null);
        leftwupingPanel.setBackground(Color.green);
        wupingPanel.add(leftwupingPanel);
        leftwupingPanel.setBounds(0, 0, 800, 300);

        rightwupingPanel = new JPanel();
        rightwupingPanel.setLayout(null);
        rightwupingPanel.setBackground(Color.blue);
        wupingPanel.add(rightwupingPanel);
        rightwupingPanel.setBounds(800, 0, 800, 300);

        //显示有那些食物
        foodLabel1 = new JTextArea();
        foodLabel1.setVisible(true);
        foodLabel1.setFont(new Font("黑体", Font.BOLD, 35));
        foodLabel1.setBounds(30, 20, 100, 50);
        foodLabel1.setText("11");
        leftwupingPanel.add(foodLabel1);
        //显示有那些道具
        daojuLabel1 = new JTextArea();
        daojuLabel1.setVisible(true);
        daojuLabel1.setFont(new Font("黑体", Font.BOLD, 35));
        daojuLabel1.setBounds(30, 20, 100, 50);
        daojuLabel1.setText("11");
        rightwupingPanel.add(daojuLabel1);
    }

    public static void main(String[] args) {

        MainInterface mainInterface = new MainInterface();
        mainInterface.setTopLabel("主角：");
        mainInterface.setevent("文本输入");
        mainInterface.setButton();
        mainInterface.setdayLabel("1") ;

    }

    JList jl;

    /**
     * 返回按钮的集合
     */
    public JList Buttonlist() {
        jl = new JList();
        jl.add(button1);
        jl.add(button2);
        jl.add(button3);
        jl.add(button4);
        return jl;
    }

    //添加按钮,返回按钮的集合
    public void setButton() {

        button1 = new JButton("1");
        button1.setBackground(Color.cyan);
        button1.setBounds(0, 0, 900, 50);
        button2 = new JButton("2");
        button2.setBackground(Color.cyan);
        button2.setBounds(0, 70, 900, 50);
        button3 = new JButton("3");
        button3.setBackground(Color.cyan);
        button3.setBounds(0, 140, 900, 50);
        button4 = new JButton("4");
        button4.setBackground(Color.cyan);
        button4.setBounds(0, 210, 900, 50);

        buttonPanel.add(button1);
        buttonPanel.add(button2);
        buttonPanel.add(button3);
        buttonPanel.add(button4);

    }

    //最上层label设置
    private void setTopLabel(String data) {
        topLabel.setText("    "+data);
        topLabel.setFont(new Font("黑体", Font.BOLD, 50));
    }

    /**
     * 天数设置
     */
    private void setdayLabel(String text) {
        dayLabel.setText("        "+text);
        dayLabel.setFont(new Font("黑体", Font.BOLD, 50));

    }


    /**
     * 事件描述输入
     */
    public void setevent(String text) {
        textArea.setText("        "+text);
        textArea.setFont(new Font("黑体", Font.BOLD, 50));

    }


    //清除选项
    private void selectClear() {
        button1.setText("");
        button2.setText("");
        button3.setText("");

    }

    //设置选项可见
    public void setVisiblebutton() {
        button1.setVisible(true);
        button2.setVisible(true);
        button3.setVisible(true);
        button4.setVisible(true);
    }

    /**
     * 事件选项输入 ,设置字体大小
     *
     * @param list
     */
    public void setButton(ArrayList<String> list) {
        button1.setFont(new Font("黑体", Font.BOLD, 100));
        button2.setFont(new Font("黑体", Font.BOLD, 100));
        button3.setFont(new Font("黑体", Font.BOLD, 100));
        button4.setFont(new Font("黑体", Font.BOLD, 100));

        if (list.size() == 4) {
            setVisiblebutton();
            for (int i = 0; i < list.size(); i++) {
                button1.setText(list.get(i));
                button2.setText(list.get(i + 1));
                button3.setText(list.get(i + 2));
                button4.setText(list.get(i + 3));

            }
        }

        if (list.size() == 3) {
            setVisiblebutton();
            for (int i = 0; i < list.size(); i++) {
                button1.setText(list.get(i));
                button2.setText(list.get(i + 1));
                button3.setText(list.get(i + 2));

                button4.setVisible(false);


            }
        }

        if (list.size() == 2) {
            setVisiblebutton();
            for (int i = 0; i < list.size(); i++) {
                button1.setText(list.get(i));
                button2.setText(list.get(i + 1));
                button3.setVisible(false);
                button4.setVisible(false);

            }
        }


    }


    //得到天数
    public String getevent() {
        return textArea.getText();
    }


    //第一个物品的get 和set方法
    public String getfoodLabel1(String text) {
        return foodLabel1.getText();
    }

    /**
     * 食物的文本设置
     *
     * @param text
     */
    public void setfoodLabel1(String text) {
        foodLabel1.setText(text);
    }
}
